@echo off
echo 🚀 正在启动Nacos集群...
echo.

REM 创建日志目录
if not exist logs mkdir logs

REM 启动4个server实例
echo 🖥️  启动节点1: 端口 8848/9090
cargo run --bin nacos-server -- --config cluster-config.toml --node node1 > logs\node1.log 2>&1 &
timeout /t 2 /nobreak > NUL

echo 🖥️  启动节点2: 端口 8849/9091
cargo run --bin nacos-server -- --config cluster-config.toml --node node2 > logs\node2.log 2>&1 &
timeout /t 2 /nobreak > NUL

echo 🖥️  启动节点3: 端口 8850/9092
cargo run --bin nacos-server -- --config cluster-config.toml --node node3 > logs\node3.log 2>&1 &
timeout /t 2 /nobreak > NUL

echo 🖥️  启动节点4: 端口 8851/9093
cargo run --bin nacos-server -- --config cluster-config.toml --node node4 > logs\node4.log 2>&1 &
timeout /t 2 /nobreak > NUL

echo.
echo ⏳ 等待集群启动...
timeout /t 5 /nobreak > NUL

echo.
echo 📊 集群状态检查:
echo.
echo 🔍 检查节点1: for /f "tokens=*" %%i in ('curl -s http://localhost:8848/health') do echo    节点1: %%i
echo 🔍 检查节点2: for /f "tokens=*" %%i in ('curl -s http://localhost:8849/health') do echo    节点2: %%i
echo 🔍 检查节点3: for /f "tokens=*" %%i in ('curl -s http://localhost:8850/health') do echo    节点3: %%i
echo 🔍 检查节点4: for /f "tokens=*" %%i in ('curl -s http://localhost:8851/health') do echo    节点4: %%i

echo.
echo ✅ 集群启动完成！
echo.
echo 📡 集群节点:
echo    节点1: http://localhost:8848 (gRPC: 9090)
echo    节点2: http://localhost:8849 (gRPC: 9091)
echo    节点3: http://localhost:8850 (gRPC: 9092)
echo    节点4: http://localhost:8851 (gRPC: 9093)
echo.
echo 🎯 接下来开始客户端测试...
pause